package com.qianli.cashmama.trade.repo.impl;

import com.qianli.cashmama.trade.dao.TBillDeductFlowDao;
import com.qianli.cashmama.trade.domain.model.DeductFlow;
import com.qianli.cashmama.trade.entity.TBillDeductFlowEntity;
import com.qianli.cashmama.trade.repo.DeductFlowRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2020/3/25
 * Time: 下午4:57
 */
@Repository
public class DeductFlowRepositoryImpl implements DeductFlowRepository {

    @Autowired
    private TBillDeductFlowDao tBillDeductFlowDao;

    /**
     * 持久化保存
     *
     * @param deductFlow
     */
    @Override
    public void store(DeductFlow deductFlow) {
        TBillDeductFlowEntity entity = new TBillDeductFlowEntity();
        BeanUtils.copyProperties(deductFlow, entity);
        tBillDeductFlowDao.insert(entity);
        deductFlow.setId(entity.getId());
    }

    /**
     * 从数据库装载
     *
     * @param id
     * @return
     */
    @Override
    public DeductFlow load(long id) {
        TBillDeductFlowEntity entity = tBillDeductFlowDao.selectByPrimaryKey(id);
        if (entity == null) {
            return null;
        }
        DeductFlow deductFlow = new DeductFlow();
        BeanUtils.copyProperties(entity, deductFlow);
        return deductFlow;
    }
}
